package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextPane;

import java.awt.Color;

import javax.swing.JEditorPane;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextField;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.border.TitledBorder;
import javax.swing.JSpinner;
import javax.swing.JSeparator;
import javax.swing.JComboBox;

public class Report extends JFrame {

	private JPanel contentPane;
	private JTextField orderNumTextField;
	private JTextField textField;
	private int counter ;


	/**
	 * Create the frame.
	 */
	public Report() {
		counter = 0;
		setTitle("Report");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(250, 30, 800, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblExplainYourProblem = new JLabel("Explain your problem");
		lblExplainYourProblem.setBounds(32, 79, 134, 16);
		contentPane.add(lblExplainYourProblem);
		
		textField = new JTextField();
		textField.setBounds(320, 235, 46, 28);
		contentPane.add(textField);
		textField.setColumns(10);

		
		final JEditorPane problemEditorPane = new JEditorPane();
		problemEditorPane.setDragEnabled(false);
		problemEditorPane.setBounds(32, 107, 401, 116);
		contentPane.add(problemEditorPane);
		problemEditorPane.addKeyListener(new KeyAdapter() {
			public void keyReleased(KeyEvent evt){
				
				char c = evt.getKeyChar();
				if (counter>9){
					if (c == 8 ){
						problemEditorPane.setEditable(true);
						counter--;
					}
					else
						problemEditorPane.setEditable(false);
				}
				else
				if ((Character.isLetterOrDigit(c))|| (c == ' ') || (c == '\t')){
					counter++;
				}
				else 
					if (c == 8 && counter>0){
						int temp = 1;
						if(problemEditorPane.getSelectedText() != null )
							temp = problemEditorPane.getSelectedText().length();
						counter -= temp;
					}
				
				textField.setText(Integer.toString(counter));
			}
		});
		
		
		
		JButton btnSend = new JButton("Send");
		btnSend.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				String problemText = new String();
				problemText = problemEditorPane.getText();
				String orderNumber = new String();
				if (problemText.isEmpty())
					JOptionPane.showMessageDialog(null, "Your Problem text are empty please fill it");
				if(orderNumber.isEmpty())
					JOptionPane.showMessageDialog(null, "Your order number NOT filled please fill it");
			}
		});
		btnSend.setBounds(71, 236, 117, 29);
		contentPane.add(btnSend);
		
		JLabel lblOrderNumber = new JLabel("Order number :");
		lblOrderNumber.setBounds(29, 29, 101, 16);
		contentPane.add(lblOrderNumber);
		
		orderNumTextField = new JTextField();
		orderNumTextField.setBounds(142, 23, 117, 28);
		contentPane.add(orderNumTextField);
		orderNumTextField.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("/1000");
		lblNewLabel.setBounds(365, 241, 61, 16);
		contentPane.add(lblNewLabel);
		


		
	}
}
